<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateCityTicketModelAPIRequest;
use App\Http\Requests\API\UpdateCityTicketModelAPIRequest;
use App\Models\CityTicketModel;
use App\Repositories\CityTicketModelRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class CityTicketModelController
 * @package App\Http\Controllers\API
 */

class CityTicketModelAPIController extends AppBaseController
{
    /** @var  CityTicketModelRepository */
    private $cityTicketModelRepository;

    public function __construct(CityTicketModelRepository $cityTicketModelRepo)
    {
        $this->cityTicketModelRepository = $cityTicketModelRepo;
    }

    /**
     * Display a listing of the CityTicketModel.
     * GET|HEAD /cityTicketModels
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->cityTicketModelRepository->pushCriteria(new RequestCriteria($request));
        $this->cityTicketModelRepository->pushCriteria(new LimitOffsetCriteria($request));
        $cityTicketModels = $this->cityTicketModelRepository->all();

        return $this->sendResponse($cityTicketModels->toArray(), 'City Ticket Models retrieved successfully');
    }

    /**
     * Store a newly created CityTicketModel in storage.
     * POST /cityTicketModels
     *
     * @param CreateCityTicketModelAPIRequest $request
     *
     * @return Response
     */
    public function store(CreateCityTicketModelAPIRequest $request)
    {
        $input = $request->all();

        $cityTicketModels = $this->cityTicketModelRepository->create($input);

        return $this->sendResponse($cityTicketModels->toArray(), 'City Ticket Model saved successfully');
    }

    /**
     * Display the specified CityTicketModel.
     * GET|HEAD /cityTicketModels/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        /** @var CityTicketModel $cityTicketModel */
        $cityTicketModel = $this->cityTicketModelRepository->findWithoutFail($id);

        if (empty($cityTicketModel)) {
            return $this->sendError('City Ticket Model not found');
        }

        return $this->sendResponse($cityTicketModel->toArray(), 'City Ticket Model retrieved successfully');
    }

    /**
     * Update the specified CityTicketModel in storage.
     * PUT/PATCH /cityTicketModels/{id}
     *
     * @param  int $id
     * @param UpdateCityTicketModelAPIRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateCityTicketModelAPIRequest $request)
    {
        $input = $request->all();

        /** @var CityTicketModel $cityTicketModel */
        $cityTicketModel = $this->cityTicketModelRepository->findWithoutFail($id);

        if (empty($cityTicketModel)) {
            return $this->sendError('City Ticket Model not found');
        }

        $cityTicketModel = $this->cityTicketModelRepository->update($input, $id);

        return $this->sendResponse($cityTicketModel->toArray(), 'CityTicketModel updated successfully');
    }

    /**
     * Remove the specified CityTicketModel from storage.
     * DELETE /cityTicketModels/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        /** @var CityTicketModel $cityTicketModel */
        $cityTicketModel = $this->cityTicketModelRepository->findWithoutFail($id);

        if (empty($cityTicketModel)) {
            return $this->sendError('City Ticket Model not found');
        }

        $cityTicketModel->delete();

        return $this->sendResponse($id, 'City Ticket Model deleted successfully');
    }
}
